package com.czh.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 模拟定时任务
 *
 * @author chenzhihua
 * @Date 2024/8/15
 */
@Component
@Slf4j
public class threadPollScheduled {
    /**
     * 每晚12点、自动生成并发送当日的销售报告
     */
    @Async("taskExecutor")
    @Scheduled(cron = "0 0 0 * * ?")
    public void generateDailySalesReport() {
        log.info("开始生成当前的报告...");
        // 模拟报告生成
        try {
            log.info("报告生成中...");
            Thread.sleep(3000); // 假设生成报告需要3秒
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        log.info("报告生成完成...");
    }
}
